package com.aabte.auth.account.domain.event;

import com.aabte.auth.account.domain.model.AccountId;
import com.aabte.auth.account.domain.model.AccountName;
import com.aabte.commons.ddd.shared.DomainEvent;
import lombok.Getter;
import lombok.ToString;

import java.util.Objects;
import java.util.UUID;

@Getter
@ToString
public class AccountCreated implements DomainEvent<AccountCreated, String> {

    private final String eventId;

    private final AccountId accountId;

    private final AccountName accountName;

    public AccountCreated(AccountId accountId, AccountName accountName) {
        this.eventId = UUID.randomUUID().toString().replaceAll("-", "");
        this.accountId = accountId;
        this.accountName = accountName;
    }

    @Override
    public boolean sameIdentityAs(AccountCreated accountCreated) {
        return this.accountId.sameValueAs(accountId);
    }

    @Override
    public String identity() {
        return eventId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        AccountCreated that = (AccountCreated) o;
        return eventId.equals(that.eventId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(eventId);
    }
}
